﻿using QLBH.DAO;
using QLBH.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QLBH.BLO
{
    class BLO_KhachHang
    {
        DAO_KhachHang DAO_kh = new DAO_KhachHang();
        public int Insert(KhachHang kh)
        {
            try
            {
	            DataTable idmax = Connection_Sql.GetDatatable("select max(ma_kh) from khachhang", false);
	            int makh = 1;
	            if (idmax.Rows[0][0].ToString()== "")
	            {
	                kh.Makh = makh.ToString();
	            }
	            else
	            {
	                kh.Makh = (int.Parse(idmax.Rows[0][0].ToString()) + 1).ToString();
	            }
	            return DAO_kh.Insert(kh);
            }
            catch (System.Exception ex)
            {
                throw new Exception("Lỗi BLO Insert: " + ex.Message);
            }
        }
    }
}
